import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/work_detail_controller.dart';
import 'package:banquanjie_app/app/widget/common/customScaffold.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import 'package:banquanjie_app/app/services/screenAdapter.dart';

class WorkDetailView extends GetView<WorkDetailController>  {
  const WorkDetailView({super.key});
  @override
  Widget build(BuildContext context) {
    return Customscaffold(
      title: '作品详情',
      
      child: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            alignment: Alignment(-1, -1),
            image: NetworkImage('https://zsjl.oss-cn-beijing.aliyuncs.com/test/xcx/works_bg.png'),
            fit: BoxFit.contain,
          ),
        ),
        child: Obx(() => controller.info.isNotEmpty ? SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children:  [
              AspectRatio(
                aspectRatio: 375 / 210,
                child: SizedBox(
                  width: double.infinity,
                  child: Swiper(
                    itemBuilder: (context, index){
                      return Container(
                        width: double.infinity,
                        height: double.infinity,
                        alignment: Alignment(0, 0),
                        child: Image.network(
                          controller.wrapper[index],
                          fit: BoxFit.contain,
                        ),
                      );
                    },
                    itemCount: controller.wrapper.length,
                    // pagination: const SwiperPagination(builder: SwiperPagination.rect),
                    // control: const SwiperControl(),
                    autoplay: false,
                    loop: false,
                  )
                )
              ),
              Transform(
                transform: Matrix4.translationValues(0.0, -ScreenAdapter.width(40), 0.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      width: ScreenAdapter.width(700),
                      padding: EdgeInsets.fromLTRB(ScreenAdapter.width(20),ScreenAdapter.width(20),ScreenAdapter.width(20),ScreenAdapter.width(0)),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(ScreenAdapter.width(10)),
                      ),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            // strutStyle: StrutStyle(
                            //   height: 1.6,
                            //   // 1.1更居中
                            //   forceStrutHeight: true, // 关键属性 强制改为文字高度
                            // ),
                            '${controller.info['Works']['worksTitle']}', 
                            style: TextStyle(height: 1.6,fontSize: ScreenAdapter.fontSize(30), fontWeight: FontWeight.w600)
                          ),
                          SizedBox(height: ScreenAdapter.width(24)),
                          RichText(
                            strutStyle: StrutStyle(
                              height: 1,
                              // leading: ScreenAdapter.width(12),
                              forceStrutHeight: true,
                            ),
                            textAlign: TextAlign.center,
                            text: TextSpan(
                              style: TextStyle(fontSize: ScreenAdapter.fontSize(24),color: Colors.black),
                              children: [
                                TextSpan(
                                  text: '${controller.info['Works']['worksTypeFirstName']} | ${controller.info['Works']['regionsName']} | ',
                                ),
                                if (controller.info['Works']['worksTypeFirst'] != 196 && controller.info['Works']['worksTypeSecond'] != 201)
                                  TextSpan(
                                    text: "${controller.info['Works']['episodes']}${controller.info['Works']['worksTypeFirst'] == 198 ? '期' : '集'} | " ,
                                  ),
                                TextSpan(text: '${ controller.timeLong.value } | '),
                                TextSpan(text: '${ controller.info['Works']['definitionLevelName']}'),
                              ]
                            )
                          ),
                          SizedBox(height: ScreenAdapter.width(28)),
                          Row(
                            children: [
                              for(int i = 0; i < controller.info['Works']['worksTypeSecondName'].split('|').length; i++)
                                Container(
                                  
                                  height: ScreenAdapter.fontSize(22) * 1.1,
                                  alignment: Alignment.center,
                                  padding: EdgeInsets.symmetric(vertical: ScreenAdapter.width(0), horizontal: ScreenAdapter.width(8)),
                                  margin: EdgeInsets.only(right: ScreenAdapter.width(8)),
                                  constraints: BoxConstraints(
                                    minWidth: ScreenAdapter.width(54)
                                  ),
                                  decoration: BoxDecoration(
                                    color: Color.fromRGBO(0,178,119,.15),
                                    borderRadius: BorderRadius.circular(ScreenAdapter.width(4))
                                  ),
                                  child: Text(style: TextStyle(height: 1, fontSize: ScreenAdapter.fontSize(22)),'${controller.info['Works']['worksTypeSecondName'].split('|')[i]}')
                                )
                            ]
                          ),
                          SizedBox(height: ScreenAdapter.height(26)),
                          Container(
                            decoration: BoxDecoration(
                              border: Border(top: BorderSide(width: 1, color: Color(0xfff4f7fc)))
                            ),
                            child: Padding(
                              padding: EdgeInsets.only(top: ScreenAdapter.height(28), bottom: ScreenAdapter.height(34)),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Expanded(
                                    flex: 1,
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.center,
                                      children: [
                                        Text('字幕', style: TextStyle(height: 1.2, fontSize: ScreenAdapter.fontSize(24), color: Color(0xff000000))),
                                        SizedBox(height: ScreenAdapter.width(6)),
                                        Text('${controller.info['Works']['captionsName']}', style: TextStyle(height: 1.2, fontSize: ScreenAdapter.fontSize(24), color: Color(0xff000000)))
                                      ],
                                    )
                                  ),
                                  Divider(color: Color(0xfff4f7fc)),
                                  Expanded(
                                    flex: 1,
                                    child:Column(
                                      crossAxisAlignment: CrossAxisAlignment.center,
                                      mainAxisAlignment: MainAxisAlignment.center,
                                      children: [
                                        Text('声道', style: TextStyle(height: 1.2, fontSize: ScreenAdapter.fontSize(24), color: Color(0xff000000))),
                                        SizedBox(height: ScreenAdapter.width(6)),
                                        Text('${controller.info['Works']['vocalTractName']}', style: TextStyle(height: 1.2, fontSize: ScreenAdapter.fontSize(24), color: Color(0xff000000)))
                                      ],
                                    )
                                  ),
                                  Divider(color: Color(0xfff4f7fc)),
                                  Expanded(
                                    flex: 1,
                                    child: Column(
                                      crossAxisAlignment: CrossAxisAlignment.center,
                                      children: [
                                        Text('介质载体', style: TextStyle(height: 1.2, fontSize: ScreenAdapter.fontSize(24), color: Color(0xff000000))),
                                        SizedBox(height: ScreenAdapter.width(6)),
                                        Text('${controller.info['Works']['mediumCarrierName']}', style: TextStyle(height: 1.2, fontSize: ScreenAdapter.fontSize(24), color: Color(0xff000000)))
                                      ],
                                    )
                                  ),
                                ],
                              )
                            ),
                          )
                        ],
                      )
                    ),
                    SizedBox(height: ScreenAdapter.height(20)),
                    Container(
                      width: ScreenAdapter.width(700),
                      padding: EdgeInsets.fromLTRB(ScreenAdapter.width(20),ScreenAdapter.width(0),ScreenAdapter.width(20),ScreenAdapter.width(20)),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(ScreenAdapter.width(10)),
                      ),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text('作品信息', strutStyle: StrutStyle(height: 3), style: TextStyle(height: 3, fontSize: ScreenAdapter.fontSize(26), fontWeight: FontWeight.w700)),
                          if(controller.info['Works']['alternateTitle'].isNotEmpty)
                            Text('又名：${controller.info['Works']['alternateTitle']}', strutStyle: StrutStyle(height: 2), style: TextStyle(height: 2, fontSize: ScreenAdapter.fontSize(26), fontWeight: FontWeight.w500)),
                          if(controller.info['Works']['worksTypeFirst'] == 198 && controller.info['Works']['distGuest'].isNotEmpty)
                            Text('嘉宾：${controller.info['Works']['distGuest']}', strutStyle: StrutStyle(height: 2), style: TextStyle(height: 2, fontSize: ScreenAdapter.fontSize(26), fontWeight: FontWeight.w500)),
                          if(![198, 200].contains(controller.info['Works']['worksTypeFirst']) && controller.info['Works']['relevName'].isNotEmpty)
                            Text('${controller.info['Works']['worksTypeFirst'] == 199 ? '配音演员：' : '演员：'}${controller.info['Works']['relevName'].replaceAll('|', '/')}', strutStyle: StrutStyle(height: 2), style: TextStyle(height: 2, fontSize: ScreenAdapter.fontSize(26), fontWeight: FontWeight.w500)),
                          if(![199].contains(controller.info['Works']['worksTypeFirst']) && controller.info['Works']['directorNames'].isNotEmpty)
                            Text('导演：${controller.info['Works']['directorNames'].replaceAll('|', ' | ')}', strutStyle: StrutStyle(height: 2), style: TextStyle(height: 2, fontSize: ScreenAdapter.fontSize(26), fontWeight: FontWeight.w500)),
                          if([198].contains(controller.info['Works']['worksTypeFirst']) && controller.info['Works']['anchor'].isNotEmpty)
                            Text('主持：${controller.info['Works']['anchor']}', strutStyle: StrutStyle(height: 2), style: TextStyle(height: 2, fontSize: ScreenAdapter.fontSize(26), fontWeight: FontWeight.w500)),
                          if([196, 197, 201, 202].contains(controller.info['Works']['worksTypeFirst']) && controller.info['Works']['writeName'].isNotEmpty)
                            Text('编剧：${controller.info['Works']['writeName']}',  style: TextStyle(height: 2, fontSize: ScreenAdapter.fontSize(26), fontWeight: FontWeight.w500)),
                          if(controller.info['Works']['licenseNumber'].isNotEmpty)
                            Text('${controller.info['Works']['worksTypeFirst'] == 196 ? '公映许可证号：' : controller.info['Works']['worksTypeFirst'] == 197 ? '发行许可证号：' : '线上备案号：'}${controller.info['Works']['licenseNumber']}',  style: TextStyle(height: 2, fontSize: ScreenAdapter.fontSize(26), fontWeight: FontWeight.w500)),

                            
                        ]
                      )
                    )
                  ],
                )
              )
            
            ],
          )
        ) : SizedBox.shrink()
        )
      )
    );
  }
}
